Modern compiler initiated code optimisation techniques attempt to detect common sub-expressions and evaluate them only once, whenever such opportunities are possible to exploit. Most compilers manage to do this only in a limited sense, and this ability varies from compiler to compiler. For example, it is sometimes recommended that common sub-expressions be placed at the beginning of the expression and/or enclosed in parentheses, and that they be written in the same way each time they occur. This recommendation is based upon the fact that a compiler will generally not recognise the common sub-expression in such simple expression pairs as:T=U+X+Y and V=(X+Y)+ZorT=U+X+Y and V=Z+X+YorT=U+X+Y and V=X+Y+Z
Many compilers do better if the same statements are organised in one of the following ways:T=X+Y+U and V=X+Y+ZorT=U+(X+Y) and V=Z+(X+Y)orT=U+(X+Y) and V=X+Y+Z
Naturally, if all computer programmers wrote their expressions in a universally recognized format and were consistent in their application of that format, then the task of the compiler would be simplified. However, human nature being what it is, this is an impossible aim. Furthermore, over time a given computer program will require modifications, corrections and the like to cope with changed external requirements, detected errors, and so on. Such changes will not always be written by the same programmer, and a later programmer may have only a rudimentary idea of the way the original (or former) programmer has expressed algebraically identical functions or rules. Thus, when the amended program comes to be recompiled, it is particularly advantageous if the compiler can recognise recently written expressions as being equivalent to earlier written expressions.